<html>
<head>
<meta http-equiv="Content-Type":content="text/html;charset=utf-8"/>
<script type="text/javascript" src="normal.js"></script>
<script type="text/javascript" language="javascript">
<!--
	//定时器获取聊天信息
	window.setInterval("getmessage()",2000);
	//获取和自己有关的信息
	function getmessage()
	{
	//创建ajax引擎
	var myhttprequest=ajaxFunction();
	//构建url
	var url="getmessage.php";
	//构建数据包
	var data="gettername=<?php 
	session_start();
	echo $_SESSION['name'];?>"+"&sendername=<?php
	echo trim($_GET['getter']);
	?>";
	//打开一个请求
	myhttprequest.open("post",url,true);
	myhttprequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//设置回调函数
	myhttprequest.onreadystatechange=function getmessagestate()
	{
		if(myhttprequest.readyState==4&&myhttprequest.status==200)
		{
			//接收数据格式json
			//document.write(myhttprequest.responseText);
			var res=myhttprequest.responseText;
			var real_res=eval("("+res+")");
			for(var i=0;i<real_res.length;i++)
			{
				$("contents").value+="发送者："+real_res[i].sender+' '+"时间:"+real_res[i].date+"\n内容:"+real_res[i].content+"\n\n";
			}
		}
	}
	//数据发送
	myhttprequest.send(data);
	}
	//ajax发送信息
	function sendmessage()
	{
		if($("con").value=="")
		{
			alert('请具体内容后再发送!!');
			return ;
		}
		//alert(document.getElementById("con").value);
		//创建ajax引擎
		var myhttprequest=ajaxFunction();
		//设置URL
		var url="sendmessage.php";
		//设置数据
		var data="content="+$("con").value+"&sender=<?php 
		echo $_SESSION['name']; ?>"+"&getter=<?php echo $_GET['getter']?>";
		//打开连接
		myhttprequest.open("post",url,true);
		myhttprequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//设置回调函数
		myhttprequest.onreadystatechange=function sendmessagestate()
		{
			if(myhttprequest.readyState==4&&myhttprequest.status==200)
			{
				$("contents").value+="发送人:<?php
			echo $_SESSION['name'];
			?>"+' '+"\r发送时间:"+new Date().toLocaleString()+"\r内容："+$("con").value+"\n\n";
				//$("contents").value="123";
			//清空发言框
			$("con").value="";
			}
		}
		//发送数据
		myhttprequest.send(data);
		//alert(info);
	}
//>
</script>
</head>
<body>
<center>
<h1><font color="red">
<?php
	echo $_SESSION['name'];
?>
正在和<font color="red">
<?php
	header("Content-Type:text/html;charset=utf-8");
	echo trim($_GET['getter']);
?>
</font> 聊天</h1><br/>
<textarea id="contents" style="height:300px;width:300px" readonly="readonly"></textarea><br/>
<input type="text" name="content" id="con"/>
<input type="button" value="发送" onclick="sendmessage()"/>
</center>
</body>
</html>